package LeetCode.NumOffer;

import java.util.Arrays;

/**
 * 和为s的两个数字
 * @author lumin
 * @date 2022/03/25 10:49
 **/
public class NumOffer57 {
    public static int[] twoSum(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int[] arr = new int[2];
        while(left < right){
            if(nums[left] + nums[right] > target){
                right--;
            }else if(nums[left] + nums[right] < target){
                left++;
            }else{
                arr[0] = nums[left];
                arr[1] = nums[right];
                break;
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] arr = {2,7,9,11};
        System.out.println(Arrays.toString(twoSum(arr,11)));
    }
}